package com.cold.demo.rabbitmq.demo2.$5.topic;

import com.cold.demo.rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.util.Date;

/**
 *
 * @author: zyc
 */
public class Publisher {
    public static String exchange = "topic_logs";

    public static void main(String[] argv) throws Exception {
        Connection connection = ConnectionUtils.getConnection();
        Channel    channel    = connection.createChannel();
        channel.exchangeDeclare(exchange, "topic");

        for (int i = 0; i < 30; i++) {
            Thread.sleep(50);
            String severity = getSeverity(argv);
            channel.basicPublish(exchange, severity, null, (System.currentTimeMillis() + "这里是消息数据" + i).getBytes());
        }
        channel.close();
        connection.close();

    }

    private static String getSeverity(String[] argv) {
        String[] routing = {
//                "quick.orange.rabbit", "lazy.orange.elephant", "quick.orange.fox",
//                "lazy.brown.fox", "lazy.pink.rabbit",
//                "quick.brown.fox",
//                "orange", "quick.orange.male.rabbit", "lazy.orange.male.rabbit",
                "kern.critical", "A critical kernel error"
        };
        return routing[(int) (System.currentTimeMillis() % routing.length)];
    }
}
